package com.donn.securitycontrolplatform.usertag.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.donn.securitycontrolplatform.common.Result;
import com.donn.securitycontrolplatform.db1.mapper.UserTagMapper;
import com.donn.securitycontrolplatform.usertag.entity.UserTag;
import com.donn.securitycontrolplatform.usertag.service.IUserTagService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户和标签关联表 服务实现类
 * </p>
 *
 * @author zhenglixiang
 * @since 2022-06-13
 */
@Service
@Slf4j
public class UserTagServiceImpl extends ServiceImpl<UserTagMapper, UserTag> implements IUserTagService {

    /**
     * 查询用户详情
     * @param userId 用户id
     * @return 返回详情
     */
    @Override
    public Result geUserTagById(String userId) {
        try {
            return Result.success(getById(userId));
        } catch (Exception e) {
            log.error("An error occurred in the getUserTagById : ", e);
            return Result.init(500, "Service error", e.getMessage());
        }
    }

    /**
     * 删除user
     * @param userId 用户标签
     * @return
     */
    @Override
    public Result deleteUserTag(String userId) {
        try {
            return Result.success(removeById(userId));
        } catch (Exception e) {
            log.error("An error occurred in the deleteUserTag : ", e);
            return Result.init(500, "Service error", e.getMessage());
        }
    }

    /**
     * 更新user
     * @param userTag
     * @return
     */
    @Override
    public Result updateUserTag(UserTag userTag) {
        try {
            return Result.success(saveOrUpdate(userTag));
        } catch (Exception e) {
            log.error("An error occurred in the updateUserTag : ", e);
            return Result.init(500, "Service error", e.getMessage());
        }
    }

    /**
     * 
     * @param userTag
     * @return
     */
    @Override
    public Result insertUserTag(UserTag userTag) {
        try {
            return Result.success(saveOrUpdate(userTag));
        } catch (Exception e) {
            log.error("An error occurred in the insertUserTag : ", e);
            return Result.init(500, "Service error", e.getMessage());
        }
    }

    @Override
    public Result selectUserTagByIds(List<String> userIds) {
        try {
            return Result.success(listByIds(userIds));
        } catch (Exception e) {
            log.error("An error occurred in the selectUserTagByIds : ", e);
            return Result.init(500, "Service error", e.getMessage());
        }
    }
}
